package com.araaya.eslimsmobile.web;



import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

@SuppressWarnings("unused")
public class TestFileUpload extends Activity {  

 private WebView mWebView;  

 private ValueCallback<Uri> mUploadMessage;  
 private final static int FILECHOOSER_RESULTCODE=1;  

 @Override  
 protected void onActivityResult(int requestCode, int resultCode,  
                                    Intent intent) {  
  if(requestCode==FILECHOOSER_RESULTCODE)  
  {  
   if (null == mUploadMessage) return;  
   Uri result = intent == null || resultCode != RESULT_OK ? null  
   : intent.getData();  
   mUploadMessage.onReceiveValue(result);  
   mUploadMessage = null;
  }  
 }  

 @Override  
 public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  

  mWebView = new WebView(this); 
  mWebView.setWebViewClient(new WebViewClient());  
  mWebView.getSettings().setJavaScriptEnabled(true);
  mWebView.loadUrl("file:///android_asset/web/index.html");
  mWebView.setWebChromeClient(new WebChromeClient() 

  {   
  @SuppressWarnings("unused")
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {  

  mUploadMessage = uploadMsg;  
  Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
  i.addCategory(Intent.CATEGORY_OPENABLE);  
  i.setType("image/*");  
  TestFileUpload.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);  

         }  
  });  

  setContentView(mWebView);  
 }

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

}

